home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Power 1997 December
/
MACPOWER-1997-12.ISO.7z
/
MACPOWER-1997-12.ISO
/
AMUG
/
PROGRAMMING
/
Raven 1.2.sit
/
Raven 1.2
/
Source
/
Foundation
/
Common
/
ZExceptions.cpp
< prev
next >
Wrap
Text File
|
1997-08-16
|
5KB
|
227 lines
/*
* File: ZExceptions.cpp
* Summary: ANSI derived exception classes.
* Written by: Jesse Jones
*
* Copyright ゥ 1996-1997 Jesse Jones.
* For conditions of distribution and use, see copyright notice in ZTypes.h
*
* Change History (most recent first):
*
* <2> 8/16/97 JDJ Uses OSStatus instead of OSErr. (OSStatus is a long).
* <1> 1/13/96 JDJ Created
*/
#include <ZExceptions.h>
#include <StdIO.h>
#include <String.h>
#include <Errors.h>
#include <Memory.h>
#include <Resources.h>
#include <ZDebug.h>
#include <ZStringUtils.h>
// ===================================================================================
// Exception Classes
// ===================================================================================
#if !HAS_ANSI_EXCEPTIONS
//---------------------------------------------------------------
//
// TBaseException::~TBaseException
//
//---------------------------------------------------------------
TBaseException::~TBaseException()
{
}
//---------------------------------------------------------------
//
// TBaseException::TBaseException
//
// Note that this uses a char buffer to avoid allocating any memory
// in the heap. (C++ will create a copy of the exception object
// when a throw statement is executed).
//
//---------------------------------------------------------------
TBaseException::TBaseException(const string& mesg)
{
short len = mesg.length();
if (len > 255)
len = 255;
BlockMoveData(mesg.c_str(), mText, len);
mText[len] = '¥0';
}
//---------------------------------------------------------------
//
// TBaseException::what
//
//---------------------------------------------------------------
const char* TBaseException::what() const
{
return mText;
}
#pragma mark -
#endif // !HAS_ANSI_EXCEPTIONS
//---------------------------------------------------------------
//
// ThrowIfNil
//
//---------------------------------------------------------------
void ThrowIfNil(const void* ptr)
{
if (ptr == nil)
throw TSysMemoryException();
}
//---------------------------------------------------------------
//
// ThrowOSErr
//
//---------------------------------------------------------------
void ThrowOSErr(OSStatus err)
{
ASSERT(err != noErr);
ThrowIfOSErr(err);
}
//---------------------------------------------------------------
//
// ThrowIfOSErr
//
//---------------------------------------------------------------
void ThrowIfOSErr(OSStatus err)
{
if (err != noErr) {
char mesg[256];
switch (err) {
case memFullErr:
throw TSysMemoryException();
break;
case resNotFound:
case resFNotFound:
case addResFailed:
case rmvResFailed:
case resAttrErr:
case mapReadErr:
sprintf(mesg, LoadRavenString("Resource error #%d").c_str(), err);
throw TSystemException(err, mesg); // ・・ハuse a TResourceException?
break;
case dirFulErr:
case dskFulErr:
case nsvErr:
case ioErr:
case fnOpnErr:
case eofErr:
case posErr:
case mFulErr:
case tmfoErr:
case fnfErr:
case wPrErr:
case fLckdErr:
case vLckdErr:
case fBsyErr:
case dupFNErr:
case opWrErr:
case rfNumErr:
case gfpErr:
case volOffLinErr:
case permErr:
case volOnLinErr:
case nsDrvErr:
case noMacDskErr:
case wrPermErr:
case dirNFErr:
case tmwdoErr:
case volGoneErr:
sprintf(mesg, LoadRavenString("File error #%d").c_str(), err);
throw TSystemException(err, mesg); // ・・ハuse a TFileException?
break;
default:
sprintf(mesg, LoadRavenString("Error #%d").c_str(), err);
throw TSystemException(err, mesg);
}
}
}
//---------------------------------------------------------------
//
// ThrowIfResError
//
//---------------------------------------------------------------
void ThrowIfResError()
{
ThrowIfOSErr(ResError());
}
//---------------------------------------------------------------
//
// ThrowIfMemError
//
//---------------------------------------------------------------
void ThrowIfMemError()
{
ThrowIfOSErr(MemError());
}
//---------------------------------------------------------------
//
// ThrowIfResFail
//
//---------------------------------------------------------------
void ThrowIfResFail(const void* ptr)
{
if (ptr == nil)
throw TSystemException(-192, "Resource was nil"); // ・・ハUse TResourceException?
ThrowIfOSErr(ResError());
}
//---------------------------------------------------------------
//
// ThrowIfMemFail
//
//---------------------------------------------------------------
void ThrowIfMemFail(const void* ptr)
{
if (ptr == nil)
throw TSysMemoryException();
ThrowIfOSErr(MemError());
}
//---------------------------------------------------------------
//
// ThrowIfQDError
//
//---------------------------------------------------------------
void ThrowIfQDError()
{
ThrowIfOSErr(QDError());
}